package com.lombardrisk.collateral.ejb3.entity.statement;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.PrimaryKeyJoinColumn;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;

import org.hibernate.annotations.GenericGenerator;

import com.lombardrisk.collateral.diary.AbstractWorkflow;
import com.lombardrisk.collateral.ejb3.entity.agreement.ColAgreementHeaderEJB3;
import com.lombardrisk.f3.identifier.KeyGenerator;

/**
 * <p>Title: 		ColWorkflowEJB3</p>
 * <p>Description: 	</p>
 * <p>Copyright: 	Copyright (c) 2008</p>
 * <p>Company: 		Lombard Risk Systems Ltd</p>
 * 
 * @author Tony Shen
 * @created 05 Aug 2008
 * @version $Revision: 1.00$
 */

@Entity
@Table(name = "ColWorkflow")
public class ColWorkflowEJB3 extends AbstractWorkflow implements java.io.Serializable {

	private static final long serialVersionUID = 3148434980128602583L;
	
	private long id;
	private ColAgreementHeaderEJB3 agreementHeader;
	private long statementId;
	private ColStatementEJB3 statement;
	private double agreedAmount;
	private String comments;
	private long actionId;
	private double marginDelvCtpy;
	private double agreementRequirement;
	private double agreementVmRequirement;
	private double agreementImRequirement;
	private String genLock;
	private boolean released;
	private boolean verified;
	private double disputeAmt;
	private boolean overWriteUserAgreedAmt;
	private long disputeAge;
	private long userDefinedCallStatus;
	private boolean used;
	private boolean todayWorkflow;
	private long notifTime;
	private boolean wrong;
	private String wrongMsg;
	//#29955 Waived Call and system calc amount overwrite 4 eye approval and system calc amount overwrite 
	private long workflowStatus;
	private int eventSource;
	private int eventValueType;
	private Date eventDate;
	private Date agreementEventDate;
	private boolean historical;
	
	private long eeInitTab;
	
	private double agreedBookingAmt;

	private double bookedVmAmt;
	
	private double bookedImAmt;

	private String groupId;
	
	private boolean intraDay;
	
	private int umbrellaType;
	private long parentId;
	private Double cptyExposure;

	private double vmReqPart1;
	private double vmReqPart2;
	private double imReqPart1;
	private double imReqPart2;
	private double vmBookedPart1;
	private double vmBookedPart2;
	private double imBookedPart1;
	private double imBookedPart2;
	
	private double vmBookedCall;      
	private double vmBookedReturn;
	private double vmBookedDelivery;   
	private double vmBookedReCall;  
	private double imBookedCall;    
	private double imBookedReturn;     
	private double imBookedDelivery;   
	private double imBookedReCall;
	
	private double agreedVMCallAmt;
	private double agreedVMRecallAmt;
	private double agreedVMDeliveryAmt;
	private double agreedVMReturnAmt;
	private double agreedIMCallAmt;
	private double agreedIMRecallAmt;
	private double agreedIMDeliveryAmt;
	private double agreedIMReturnAmt;
	   
	private boolean fcm;
	
	private boolean expStdApplied;
	
	//#1225 R19
	private Date valuationDate;
	
	private ColWorkflowProcEJB3 workflowProc;

	/**
	 * CAUTION!!
	 * these 2 fields(lastupdatedby, lastupdatedtime) only indicate the modification of the
	 * overwriting the agreedAmount and changing the  marginCallStatus.
	 * 
	 * modification of other fields will not trigger the value change of these 2 fields. 
	 * 
	 */
	
	private String lastUpdatedBy;
	
	private Date lastUpdatedTime;
	
	/**
	 * generate a new key value and set it to the id field
	 */
	public void makeNewKey() {
		KeyGenerator keyGenerator = new KeyGenerator();
		long newId = keyGenerator.generateKey("com.lombardrisk.collateral.diary.ColWorkflowCMP");
		setId(newId);
	}

	@Id
	@GenericGenerator(name = "manualAssign", parameters = {}, strategy = "assigned")
	@GeneratedValue(generator = "manualAssign")
	@Column(name = "id", unique = true, nullable = false)
	public long getId() {
		return this.id;
	}

	public void setId(long id) {
		this.id = id;
	}

	@ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name="agreementId", nullable = false, updatable = false)
    @org.hibernate.annotations.Fetch(org.hibernate.annotations.FetchMode.JOIN)
	public ColAgreementHeaderEJB3 getAgreementHeader() {
		return agreementHeader;
	}

	public void setAgreementHeader(ColAgreementHeaderEJB3 agreementHeader) {
		this.agreementHeader = agreementHeader;
	}
	
	
	
	@ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name="statementId", updatable = false , insertable = false)
//    @org.hibernate.annotations.Fetch(org.hibernate.annotations.FetchMode.JOIN)
	public ColStatementEJB3 getStatement() {
		return statement;
	}
	
	public void setStatement(ColStatementEJB3 statement) {
		this.statement = statement;
	}

	@Column(name = "statementId", updatable = false)
	public long getStatementId() {
		return statementId;
	}

	public void setStatementId(long statementId) {
		this.statementId = statementId;
	}

	@Column(name = "agreedAmount", precision = 53, scale = 0)
	public double getAgreedAmount() {
		return this.agreedAmount;
	}

	public void setAgreedAmount(double agreedAmount) {
		this.agreedAmount = agreedAmount;
	}

	@Column(name = "comments", length = 250)
	public String getComments() {
		return this.comments;
	}

	public void setComments(String comments) {
		this.comments = comments;
	}

	@Column(name = "actionId")
	public long getActionId() {
		return this.actionId;
	}

	public void setActionId(long actionId) {
		this.actionId = actionId;
	}

	@Column(name = "marginDelvCtpy", precision = 53, scale = 0)
	public double getMarginDelvCtpy() {
		return this.marginDelvCtpy;
	}

	public void setMarginDelvCtpy(double marginDelvCtpy) {
		this.marginDelvCtpy = marginDelvCtpy;
	}

	@Column(name = "AgreementRequirement", precision = 53, scale = 0)
	public double getAgreementRequirement() {
		return this.agreementRequirement;
	}

	public void setAgreementRequirement(double agreementRequirement) {
		this.agreementRequirement = agreementRequirement;
	}
	
	@Column(name = "agreementVmRequirement", precision = 53, scale = 0)
	public double getAgreementVmRequirement() {
		return this.agreementVmRequirement;
	}

	public void setAgreementVmRequirement(double agreementVmRequirement) {
		this.agreementVmRequirement = agreementVmRequirement;
	}
	
	@Column(name = "agreementImRequirement", precision = 53, scale = 0)
	public double getAgreementImRequirement() {
		return this.agreementImRequirement;
	}

	public void setAgreementImRequirement(double agreementImRequirement) {
		this.agreementImRequirement = agreementImRequirement;
	}

	@Column(name = "genLock", length = 32)
	public String getGenLock() {
		return this.genLock;
	}

	public void setGenLock(String genLock) {
		this.genLock = genLock;
	}

	@Column(name = "released")
	public boolean isReleased() {
		return this.released;
	}

	public void setReleased(boolean released) {
		this.released = released;
	}

	@Column(name = "verified")
	public boolean isVerified() {
		return this.verified;
	}

	public void setVerified(boolean verified) {
		this.verified = verified;
	}

	@Column(name = "disputeAmt", precision = 53, scale = 0)
	public double getDisputeAmt() {
		return this.disputeAmt;
	}

	public void setDisputeAmt(double disputeAmt) {
		this.disputeAmt = disputeAmt;
	}

	@Column(name = "overWriteUserAgreedAmt")
	public boolean isOverWriteUserAgreedAmt() {
		return this.overWriteUserAgreedAmt;
	}

	public void setOverWriteUserAgreedAmt(boolean overWriteUserAgreedAmt) {
		this.overWriteUserAgreedAmt = overWriteUserAgreedAmt;
	}

	@Column(name = "disputeAge")
	public long getDisputeAge() {
		return this.disputeAge;
	}

	public void setDisputeAge(long disputeAge) {
		this.disputeAge = disputeAge;
	}

	@Column(name = "userDefinedCallStatus")
	public long getUserDefinedCallStatus() {
		return this.userDefinedCallStatus;
	}

	public void setUserDefinedCallStatus(long userDefinedCallStatus) {
		this.userDefinedCallStatus = userDefinedCallStatus;
	}

	@Column(name = "used")
	public boolean isUsed() {
		return this.used;
	}

	public void setUsed(boolean used) {
		this.used = used;
	}

	@Column(name = "todayWorkflow")
	public boolean isTodayWorkflow() {
		return todayWorkflow;
	}

	public void setTodayWorkflow(boolean todayWorkflow) {
		this.todayWorkflow = todayWorkflow;
	}

	@Column(name = "notifTime")
	public long getNotifTime() {
		return notifTime;
	}

	public void setNotifTime(long notifTime) {
		this.notifTime = notifTime;
	}

	@Column(name = "wrong")
	public boolean isWrong() {
		return wrong;
	}

	public void setWrong(boolean wrong) {
		this.wrong = wrong;
	}

	@Column(name = "wrongMsg")
	public String getWrongMsg() {
		return wrongMsg;
	}

	public void setWrongMsg(String wrongMsg) {
		this.wrongMsg = wrongMsg;
	}
	
	@Column(name = "workflowStatus")
	public long getWorkflowStatus() {
		return workflowStatus;
	}

	public void setWorkflowStatus(long workflowStatus) {
		this.workflowStatus = workflowStatus;
	}

	@Column(name = "eventSource")
	public int getEventSource() {
		return eventSource;
	}

	public void setEventSource(int eventSource) {
		this.eventSource = eventSource;
	}

	@Column(name = "eventValueType")
	public int getEventValueType() {
		return eventValueType;
	}

	public void setEventValueType(int eventValueType) {
		this.eventValueType = eventValueType;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "eventDate")
	public Date getEventDate() {
		return eventDate;
	}

	public void setEventDate(Date eventDate) {
		this.eventDate = eventDate;
	}
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "agreementEventDate")
	public Date getAgreementEventDate() {
		return agreementEventDate;
	}

	public void setAgreementEventDate(Date agreementEventDate) {
		this.agreementEventDate = agreementEventDate;
	}

	@Column(name = "historical")
	public boolean isHistorical() {
		return historical;
	}

	public void setHistorical(boolean historical) {
		this.historical = historical;
	}

	@Column(name = "eeInitTab")
	public long getEeInitTab() {
		return eeInitTab;
	}

	public void setEeInitTab(long eeInitTab) {
		this.eeInitTab = eeInitTab;
	}

	@Column(name = "LastUpdatedBy")
	public String getLastUpdatedBy() {
		return lastUpdatedBy;
	}

	public void setLastUpdatedBy(String lastUpdatedBy) {
		this.lastUpdatedBy = lastUpdatedBy;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "LastUpdatedTime")
	public Date getLastUpdatedTime() {
		return lastUpdatedTime;
	}

	public void setLastUpdatedTime(Date lastUpdatedTime) {
		this.lastUpdatedTime = lastUpdatedTime;
	}
	
	@Column(name = "agreedBookingAmt", precision = 53, scale = 0)
	public double getAgreedBookingAmt() {
		return agreedBookingAmt;
	}

	public void setAgreedBookingAmt(double agreedBookingAmt) {
		this.agreedBookingAmt = agreedBookingAmt;
	}

	@Column(name = "bookedVmAmt", precision = 53, scale = 0)
	public double getBookedVmAmt() {
		return bookedVmAmt;
	}

	public void setBookedVmAmt(double bookedVmAmt) {
		this.bookedVmAmt = bookedVmAmt;
	}
	
	@Column(name = "bookedImAmt", precision = 53, scale = 0)
	public double getBookedImAmt() {
		return bookedImAmt;
	}

	public void setBookedImAmt(double bookedImAmt) {
		this.bookedImAmt = bookedImAmt;
	}

	@Column(name = "groupId", length = 50)
	public String getGroupId() {
		return groupId;
	}

	public void setGroupId(String groupId) {
		this.groupId = groupId;
	}

	@Column(name = "intraDay")
	public boolean isIntraDay() {
		return intraDay;
	}

	public void setIntraDay(boolean intraDay) {
		this.intraDay = intraDay;
	}

	@OneToOne(optional = false, fetch = FetchType.EAGER)
	@PrimaryKeyJoinColumn
	@org.hibernate.annotations.Fetch(org.hibernate.annotations.FetchMode.JOIN)
	@JoinColumn(name = "id", nullable = false)
	public ColWorkflowProcEJB3 getWorkflowProc() {
		return workflowProc;
	}

	public void setWorkflowProc(ColWorkflowProcEJB3 workflowProc) {
		this.workflowProc = workflowProc;
	}

	@Transient
	public Date getIssueDate() {
		return workflowProc.getIssueDate();
	}

	@Transient
	public double getIssuedValue() {
		return workflowProc.getIssuedValue();
	}

	@Transient
	public long getMarginCallStatus() {
		return workflowProc.getMarginCallStatus();
	}
	
	@Transient
	public String getDeliveryStatus() {
		return workflowProc.getDeliveryStatus();
	}

	@Transient
	public long getNotificationStatus() {
		return workflowProc.getNotificationStatus();
	}
	
	@Column(name = "umbrellaType")
	public int getUmbrellaType() {
		return umbrellaType;
	}

	public void setUmbrellaType(int umbrellaType) {
		this.umbrellaType = umbrellaType;
	}

	@Column(name = "parentId")
	public long getParentId() {
		return parentId;
	}

	public void setParentId(long parentId) {
		this.parentId = parentId;
	}

	@Column(name = "cptyExposure")
	public Double getCptyExposure() {
		return cptyExposure;
	}

	public void setCptyExposure(Double cptyExposure) {
		this.cptyExposure = cptyExposure;
	}

	@Column(name = "vmReqPart1")
	public double getVmReqPart1() {
		return vmReqPart1;
	}

	public void setVmReqPart1(double vmReqPart1) {
		this.vmReqPart1 = vmReqPart1;
	}

	@Column(name = "vmReqPart2")
	public double getVmReqPart2() {
		return vmReqPart2;
	}

	public void setVmReqPart2(double vmReqPart2) {
		this.vmReqPart2 = vmReqPart2;
	}

	@Column(name = "imReqPart1")
	public double getImReqPart1() {
		return imReqPart1;
	}

	public void setImReqPart1(double imReqPart1) {
		this.imReqPart1 = imReqPart1;
	}

	@Column(name = "imReqPart2")
	public double getImReqPart2() {
		return imReqPart2;
	}

	public void setImReqPart2(double imReqPart2) {
		this.imReqPart2 = imReqPart2;
	}

	@Column(name = "vmBookedPart1")
	public double getVmBookedPart1() {
		return vmBookedPart1;
	}

	public void setVmBookedPart1(double vmBookedPart1) {
		this.vmBookedPart1 = vmBookedPart1;
	}

	@Column(name = "vmBookedPart2")
	public double getVmBookedPart2() {
		return vmBookedPart2;
	}

	public void setVmBookedPart2(double vmBookedPart2) {
		this.vmBookedPart2 = vmBookedPart2;
	}

	@Column(name = "imBookedPart1")
	public double getImBookedPart1() {
		return imBookedPart1;
	}

	public void setImBookedPart1(double imBookedPart1) {
		this.imBookedPart1 = imBookedPart1;
	}

	@Column(name = "imBookedPart2")
	public double getImBookedPart2() {
		return imBookedPart2;
	}

	public void setImBookedPart2(double imBookedPart2) {
		this.imBookedPart2 = imBookedPart2;
	}

	@Column(name = "fcm")
	public boolean isFcm() {
		return fcm;
	}

	public void setFcm(boolean fcm) {
		this.fcm = fcm;
	}

	@Column(name = "vmBookedCall")
	public double getVmBookedCall() {
		return vmBookedCall;
	}

	public void setVmBookedCall(double vmBookedCall) {
		this.vmBookedCall = vmBookedCall;
	}

	@Column(name = "vmBookedReturn")
	public double getVmBookedReturn() {
		return vmBookedReturn;
	}

	public void setVmBookedReturn(double vmBookedReturn) {
		this.vmBookedReturn = vmBookedReturn;
	}

	@Column(name = "vmBookedDelivery")
	public double getVmBookedDelivery() {
		return vmBookedDelivery;
	}

	public void setVmBookedDelivery(double vmBookedDelivery) {
		this.vmBookedDelivery = vmBookedDelivery;
	}

	@Column(name = "vmBookedReCall")
	public double getVmBookedReCall() {
		return vmBookedReCall;
	}

	public void setVmBookedReCall(double vmBookedReCall) {
		this.vmBookedReCall = vmBookedReCall;
	}

	@Column(name = "imBookedCall")
	public double getImBookedCall() {
		return imBookedCall;
	}

	public void setImBookedCall(double imBookedCall) {
		this.imBookedCall = imBookedCall;
	}

	@Column(name = "imBookedReturn")
	public double getImBookedReturn() {
		return imBookedReturn;
	}

	public void setImBookedReturn(double imBookedReturn) {
		this.imBookedReturn = imBookedReturn;
	}

	@Column(name = "imBookedDelivery")
	public double getImBookedDelivery() {
		return imBookedDelivery;
	}

	public void setImBookedDelivery(double imBookedDelivery) {
		this.imBookedDelivery = imBookedDelivery;
	}

	@Column(name = "imBookedReCall")
	public double getImBookedReCall() {
		return imBookedReCall;
	}

	public void setImBookedReCall(double imBookedReCall) {
		this.imBookedReCall = imBookedReCall;
	}

	@Override
	@Transient
	public long getAgreementId() {
		return agreementHeader.getId();
	}

	@Column(name = "agreedVMCallAmt")
	public double getAgreedVMCallAmt() {
		return this.agreedVMCallAmt;
	}

	public void setAgreedVMCallAmt(double agreedVMCallAmt) {
		this.agreedVMCallAmt = agreedVMCallAmt;
		
	}

	@Column(name = "agreedVMRecallAmt")
	public double getAgreedVMRecallAmt() {
		return this.agreedVMRecallAmt;
	}

	@Override
	public void setAgreedVMRecallAmt(double agreedVMRecallAmt) {
		this.agreedVMRecallAmt = agreedVMRecallAmt;
	}

	@Column(name = "agreedVMDeliveryAmt")
	public double getAgreedVMDeliveryAmt() {
		return this.agreedVMDeliveryAmt;
	}

	@Override
	public void setAgreedVMDeliveryAmt(double agreedVMDeliveryAmt) {
		this.agreedVMDeliveryAmt = agreedVMDeliveryAmt;
	}

	@Column(name = "agreedVMReturnAmt")
	public double getAgreedVMReturnAmt() {
		return this.agreedVMReturnAmt;
	}

	@Override
	public void setAgreedVMReturnAmt(double agreedVMReturnAmt) {
		this.agreedVMReturnAmt = agreedVMReturnAmt;
	}

	@Column(name = "agreedIMCallAmt")
	public double getAgreedIMCallAmt() {
		return this.agreedIMCallAmt;
	}

	public void setAgreedIMCallAmt(double agreedIMCallAmt) {
		this.agreedIMCallAmt = agreedIMCallAmt;
	}

	@Column(name = "agreedIMRecallAmt")
	public double getAgreedIMRecallAmt() {
		return this.agreedIMRecallAmt;
	}

	public void setAgreedIMRecallAmt(double agreedIMRecallAmt) {
		this.agreedIMRecallAmt = agreedIMRecallAmt;
	}

	@Column(name = "agreedIMDeliveryAmt")
	public double getAgreedIMDeliveryAmt() {
		return this.agreedIMDeliveryAmt;
	}

	public void setAgreedIMDeliveryAmt(double agreedIMDeliveryAmt) {
		this.agreedIMDeliveryAmt = agreedIMDeliveryAmt;
	}

	@Column(name = "agreedIMReturnAmt")
	public double getAgreedIMReturnAmt() {
		return this.agreedIMReturnAmt;
	}

	public void setAgreedIMReturnAmt(double agreedIMReturnAmt) {
		this.agreedIMReturnAmt = agreedIMReturnAmt;
	}
	@Column(name = "expStdApplied")
	public boolean getExpStdApplied() {
		return expStdApplied;
	}

	public void setExpStdApplied(boolean expStdApplied) {
		this.expStdApplied = expStdApplied;
	}

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "cobValuationDate")
	public Date getValuationDate() {
		return valuationDate;
	}

	public void setValuationDate(Date valuationDate) {
		this.valuationDate = valuationDate;
	}
}